<template>
  <div class="app-container">
<!--    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">-->
<!--      <el-form-item label="站点id" prop="siteId">-->
<!--        <el-input-->
<!--          v-model="queryParams.siteId"-->
<!--          placeholder="请输入站点id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="语言id" prop="langId">-->
<!--        <el-input-->
<!--          v-model="queryParams.langId"-->
<!--          placeholder="请输入语言id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="分类id" prop="categoryIds">-->
<!--        <el-input-->
<!--          v-model="queryParams.categoryIds"-->
<!--          placeholder="请输入分类id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="标题" prop="title">-->
<!--        <el-input-->
<!--          v-model="queryParams.title"-->
<!--          placeholder="请输入标题"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="副标题" prop="subtitle">-->
<!--        <el-input-->
<!--          v-model="queryParams.subtitle"-->
<!--          placeholder="请输入副标题"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="简介" prop="description">-->
<!--        <el-input-->
<!--          v-model="queryParams.description"-->
<!--          placeholder="请输入简介"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="标签" prop="tags">-->
<!--        <el-input-->
<!--          v-model="queryParams.tags"-->
<!--          placeholder="请输入标签"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="价格" prop="price">-->
<!--        <el-input-->
<!--          v-model="queryParams.price"-->
<!--          placeholder="请输入价格"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="VIP价格" prop="vprice">-->
<!--        <el-input-->
<!--          v-model="queryParams.vprice"-->
<!--          placeholder="请输入VIP价格"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="总集数" prop="episodes">-->
<!--        <el-input-->
<!--          v-model="queryParams.episodes"-->
<!--          placeholder="请输入总集数"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="评分" prop="score">-->
<!--        <el-input-->
<!--          v-model="queryParams.score"-->
<!--          placeholder="请输入评分"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="销量" prop="sales">-->
<!--        <el-input-->
<!--          v-model="queryParams.sales"-->
<!--          placeholder="请输入销量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="收藏量" prop="favorites">-->
<!--        <el-input-->
<!--          v-model="queryParams.favorites"-->
<!--          placeholder="请输入收藏量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="播放量" prop="views">-->
<!--        <el-input-->
<!--          v-model="queryParams.views"-->
<!--          placeholder="请输入播放量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="转发量" prop="shares">-->
<!--        <el-input-->
<!--          v-model="queryParams.shares"-->
<!--          placeholder="请输入转发量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="点赞量" prop="likes">-->
<!--        <el-input-->
<!--          v-model="queryParams.likes"-->
<!--          placeholder="请输入点赞量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="虚拟播放量" prop="fakeViews">-->
<!--        <el-input-->
<!--          v-model="queryParams.fakeViews"-->
<!--          placeholder="请输入虚拟播放量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="虚拟收藏量" prop="fakeFavorites">-->
<!--        <el-input-->
<!--          v-model="queryParams.fakeFavorites"-->
<!--          placeholder="请输入虚拟收藏量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="虚拟转发量" prop="fakeShares">-->
<!--        <el-input-->
<!--          v-model="queryParams.fakeShares"-->
<!--          placeholder="请输入虚拟转发量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="虚拟点赞量" prop="fakeLikes">-->
<!--        <el-input-->
<!--          v-model="queryParams.fakeLikes"-->
<!--          placeholder="请输入虚拟点赞量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="排序" prop="weigh">-->
<!--        <el-input-->
<!--          v-model="queryParams.weigh"-->
<!--          placeholder="请输入排序"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="版权方" prop="copyrightId">-->
<!--        <el-input-->
<!--          v-model="queryParams.copyrightId"-->
<!--          placeholder="请输入版权方"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="添加时间" prop="createtime">-->
<!--        <el-input-->
<!--          v-model="queryParams.createtime"-->
<!--          placeholder="请输入添加时间"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="更新时间" prop="updatetime">-->
<!--        <el-input-->
<!--          v-model="queryParams.updatetime"-->
<!--          placeholder="请输入更新时间"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="删除时间" prop="deletetime">-->
<!--        <el-input-->
<!--          v-model="queryParams.deletetime"-->
<!--          placeholder="请输入删除时间"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item>-->
<!--        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
<!--        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
<!--      </el-form-item>-->
<!--    </el-form>-->

    <div>
      <el-switch v-model="switchValue" inactive-text="筛选条件" style="margin-bottom: 10px" />
      <div v-if="switchValue">
        <span style="margin-right: 10px;font-size: 14px">语言</span>
        <!-- 搜索条件内容 -->
        <el-radio-group v-model="langValue" @change="getCategoryByLangList">
          <el-radio-button :label="''">全部</el-radio-button>
          <el-radio-button v-for="item in langList" :label="item.id+''" >{{ item.langCn }}</el-radio-button>
        </el-radio-group>
        <br>
        <div v-if="langValue != ''" style="margin-top: 20px">
          <span style="margin-right: 10px;font-size: 14px">分类</span>
          <el-radio-group v-model="categoryValue" @change="getCategoryList">
            <el-radio-button :label="''">全部</el-radio-button>
            <el-radio-button v-if="langValue != '0'" v-for="item in categoryList" :label="item.id+''" >
              {{ item.name }}
            </el-radio-button>
          </el-radio-group>
        </div>
        <br>
        <span style="margin-right: 10px;font-size: 14px">标志</span>
        <el-radio-group v-model="flagValue" @change="getFlagList">
          <el-radio-button :label="''">全部</el-radio-button>
          <el-radio-button :label="'hot'">热门</el-radio-button>
          <el-radio-button :label="'recommend'">推荐</el-radio-button>
        </el-radio-group>
        <br>
        <div style="margin-top: 20px">
          <span style="margin-right: 10px;font-size: 14px">价格</span>
          <el-input placeholder="请输入最低积分" v-model="queryParams.minprice">
            <template slot="append">积分</template>
          </el-input>
          -
          <el-input placeholder="请输入最高积分" v-model="queryParams.maxprice">
            <template slot="append">积分</template>
          </el-input>
        </div>
        <br>
        <div style="margin-bottom: 20px">
          <span style="margin-right: 10px;font-size: 14px">VIP价格</span>
          <el-input placeholder="请输入VIP最低积分" v-model="queryParams.minvprice">
            <template slot="append">积分</template>
          </el-input>
          -
          <el-input placeholder="请输入VIP最高积分" v-model="queryParams.maxvprice">
            <template slot="append">积分</template>
          </el-input>
        </div>
        <div style="margin-bottom: 20px">
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">筛选条件</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </div>
      </div>

    </div>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          @click="openBatchDialog"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
      <el-col :span="2.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="importEpisodes"
        >导入剧集到本地服务器</el-button>
      </el-col>
      <el-col :span="2.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="importOss"
        >导入剧集到oss服务器</el-button>
      </el-col>
      <el-col :span="3">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="upload.open = true"
        >导入Excel</el-button>
      </el-col>

      <el-col :span="12" style="text-align: right">
        <el-button
          icon="el-icon-delete"
          size="mini"
          @click="handleOpenDelete"
        >回收站</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    </el-row>

    <el-table v-loading="loading" :data="videoList" stripe>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
<!--      <el-table-column label="站点id" align="center" prop="siteId" />-->
      <el-table-column label="语言" align="center" prop="langName" />
<!--      <el-table-column label="分类id" align="center" prop="categoryIds" />-->
<!--      <el-table-column label="地区" align="center" prop="areaId" />-->
<!--      <el-table-column label="年份" align="center" prop="yearId" />-->
      <el-table-column label="标题" width="300px" align="center" prop="title" >
        <template slot-scope="scope" style="display: flex; align-items: center;">
          <el-row :gutter="20">
            <el-col :span="4">
              <image-preview :src="scope.row.image" :width="50" :height="50"/>
            </el-col>
            <el-col :span="20">
              <el-row>
                {{ scope.row.title }}
              </el-row>
              <el-row>
                <el-tag style="margin-right: 5px" type="warning" v-for="tag in scope.row.flagList">{{ tag }}</el-tag>
                <el-tag style="margin-right: 5px" v-for="tag in scope.row.categoryNames">{{ tag.name }}</el-tag>
              </el-row>
            </el-col>
          </el-row>
        </template>
      </el-table-column>
      <el-table-column label="副标题" align="center" prop="subtitle" show-overflow-tooltip />
<!--      <el-table-column label="封面" align="center" prop="image" width="100">-->
<!--        <template slot-scope="scope">-->
<!--          <image-preview :src="scope.row.image" :width="50" :height="50"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="标志" align="center" prop="flags" />-->
      <el-table-column label="简介" align="center" prop="description" show-overflow-tooltip />
<!--      <el-table-column label="标签" align="center" prop="tags" />-->
<!--      <el-table-column label="图文详情" align="center" prop="content" show-overflow-tooltip />-->
      <el-table-column label="积分价格" align="center" prop="price" />
      <el-table-column label="VIP积分价格" align="center" prop="vprice" />
      <el-table-column label="总集数" align="center" prop="episodes" />
      <el-table-column label="评分" align="center" prop="score" />
      <el-table-column label="销量" align="center" prop="sales" />
      <el-table-column label="收藏量" align="center" prop="favorites" />
      <el-table-column label="播放量" align="center" prop="views" />
      <el-table-column label="转发量" align="center" prop="shares" />
      <el-table-column label="点赞量" align="center" prop="likes" />
<!--      <el-table-column label="虚拟播放量" align="center" prop="fakeViews" />-->
<!--      <el-table-column label="虚拟收藏量" align="center" prop="fakeFavorites" />-->
<!--      <el-table-column label="虚拟转发量" align="center" prop="fakeShares" />-->
<!--      <el-table-column label="虚拟点赞量" align="center" prop="fakeLikes" />-->
      <el-table-column label="序号" align="center" prop="weigh" />
<!--      <el-table-column label="商品状态:up=上架,down=下架" align="center" prop="status" />-->
<!--      <el-table-column label="版权方" align="center" prop="copyrightId" />-->
<!--      <el-table-column label="添加时间" align="center" prop="createtime" />-->
<!--      <el-table-column label="更新时间" align="center" prop="updatetime" />-->
<!--      <el-table-column label="删除时间" align="center" prop="deletetime" />-->
      <el-table-column fixed="right" width="150px" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.status == 'down'"
            size="mini"
            type="text"
            @click="handleUpDown(scope.row,'up')"
          >上架</el-button>
          <el-button
            v-if="scope.row.status == 'up'"
            size="mini"
            type="text"
            class="downClass"
            @click="handleUpDown(scope.row,'down')"
          >下架</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleCopy(scope.row)"
          >复制</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleChangeDel(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 批量修改短剧价格 -->
    <el-dialog title="批量设置价格" :visible.sync="openBatch" width="800px" append-to-body :lock-scroll="false" :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form ref="form" :model="batchForm" label-width="120px">
        <el-form-item label="整剧用户价格" prop="title">
          <el-input v-model="batchForm.price" placeholder="不修改留空" >
            <template slot="append">积分</template>
          </el-input>
        </el-form-item>
        <el-form-item label="单集用户价格" prop="title">
          <el-input v-model="batchForm.limit">
            <template slot="prepend">前</template>
            <template slot="append">集</template>
          </el-input>
          <el-input v-model="batchForm.paid" placeholder="不修改留空" >
            <template slot="append">积分</template>
          </el-input>
          <el-input v-model="batchForm.paids">
            <template slot="prepend">其余</template>
            <template slot="append">积分</template>
          </el-input>
        </el-form-item>
        <div v-show="!checkedBatch">
          <el-form-item label="整剧VIP用户价格" prop="title">
            <el-input v-model="batchForm.vprice" placeholder="不修改留空" >
              <template slot="append">积分</template>
            </el-input>
          </el-form-item>
          <el-form-item label="单集VIP用户价格" prop="title">
            <el-input v-model="batchForm.vlimit">
              <template slot="prepend">前</template>
              <template slot="append">集</template>
            </el-input>
            <el-input v-model="batchForm.vpaid" placeholder="不修改留空" >
              <template slot="append">积分</template>
            </el-input>
            <el-input v-model="batchForm.vpaids">
              <template slot="prepend">其余</template>
              <template slot="append">积分</template>
            </el-input>
          </el-form-item>
        </div>
      </el-form>
      <template slot="footer">
        <div style="display: inline-block;text-align: left;width: 160px">
          <el-checkbox v-model="checkedBatch" @change="changeVip">VIP用户免费</el-checkbox>
        </div>
        <div style="display: inline-block;text-align: right;width: 600px">
          <el-button @click="cancelBatch">取 消</el-button>
          <el-button type="primary" @click="batchUpdateVideo">确 定</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 添加或修改短剧对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <div style="height: 500px;overflow: auto;padding: 0 10px">
        <!-- 步骤条 -->
        <el-steps :active="currentStep" simple style="margin-bottom: 10px">
          <el-step title="基础信息" icon="''"></el-step>
          <el-step title="剧集" icon="''"></el-step>
          <el-step title="短剧详情" icon="''"></el-step>
        </el-steps>
        <el-form v-show="currentStep == 0" ref="form" :model="form" :rules="rules" label-width="110px">
<!--          <el-form-item label="站点id" prop="siteId">-->
<!--            <el-input v-model="form.siteId" placeholder="请输入站点id" />-->
<!--          </el-form-item>-->
          <el-form-item label="语言" prop="langId">
            <el-select v-model="form.langId" placeholder="请选择" @change="changeLangCategory">
              <el-option
                v-for="item in langList"
                :key="item.id"
                :label="item.langCn"
                :value="item.id">
              </el-option>
            </el-select>
            <span style="margin-left: 10px;color: #5a5e66">该剧属于哪个语言分类</span>
          </el-form-item>
          <el-form-item label="视频分类" prop="categoryIds">
            <el-select v-model="categories" multiple placeholder="请选择">
              <el-option
                v-for="item in cList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
            <span style="margin-left: 10px;color: #5a5e66">可多选</span>
          </el-form-item>
          <el-form-item label="标志" prop="categoryIds">
            <el-select v-model="flagArray" multiple placeholder="请选择">
              <el-option label="热门" value="hot"/>
              <el-option label="推荐" value="recommend"/>
            </el-select>
            <span style="margin-left: 10px;color: #5a5e66">热门：首页分类显示，推荐：搜索页推荐显示</span>
          </el-form-item>
          <el-form-item label="标题" prop="title">
            <el-input v-model="form.title" style="width: 222px !important" placeholder="请输入标题" />
            <span style="margin-left: 10px;color: #5a5e66">剧名</span>
          </el-form-item>
          <el-form-item label="副标题" prop="subtitle">
            <el-input v-model="form.subtitle" type="textarea" :rows="3" placeholder="请输入副标题" />
          </el-form-item>
          <el-form-item label="封面" prop="image">
            <image-upload v-model="form.image"/>
          </el-form-item>
          <el-form-item label="积分价格" prop="price">
            <el-input v-model="form.price" placeholder="请输入价格" />
          </el-form-item>
          <el-form-item label="VIP积分价格" prop="vprice">
            <el-input v-model="form.vprice" placeholder="请输入VIP价格" />
          </el-form-item>
          <el-form-item label="总集数" prop="episodes">
            <el-input v-model="form.episodes" placeholder="请输入总集数" />
          </el-form-item>
          <el-form-item label="评分" prop="score">
            <el-input v-model="form.score" placeholder="请输入评分" />
          </el-form-item>
          <!--        <el-form-item label="销量" prop="sales">-->
          <!--          <el-input v-model="form.sales" placeholder="请输入销量" />-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="收藏量" prop="favorites">-->
          <!--          <el-input v-model="form.favorites" placeholder="请输入收藏量" />-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="播放量" prop="views">-->
          <!--          <el-input v-model="form.views" placeholder="请输入播放量" />-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="转发量" prop="shares">-->
          <!--          <el-input v-model="form.shares" placeholder="请输入转发量" />-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="点赞量" prop="likes">-->
          <!--          <el-input v-model="form.likes" placeholder="请输入点赞量" />-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="虚拟播放量" prop="fakeViews">-->
          <!--          <el-input v-model="form.fakeViews" placeholder="请输入虚拟播放量" />-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="虚拟收藏量" prop="fakeFavorites">-->
          <!--          <el-input v-model="form.fakeFavorites" placeholder="请输入虚拟收藏量" />-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="虚拟转发量" prop="fakeShares">-->
          <!--          <el-input v-model="form.fakeShares" placeholder="请输入虚拟转发量" />-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="虚拟点赞量" prop="fakeLikes">-->
          <!--          <el-input v-model="form.fakeLikes" placeholder="请输入虚拟点赞量" />-->
          <!--        </el-form-item>-->
          <el-form-item label="排序号" prop="weigh">
            <el-input v-model="form.weigh" placeholder="请输入排序号" />
          </el-form-item>
          <!--        <el-form-item label="版权方" prop="copyrightId">-->
          <!--          <el-input v-model="form.copyrightId" placeholder="请输入版权方" />-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="删除时间" prop="deletetime">-->
          <!--          <el-input v-model="form.deletetime" placeholder="请输入删除时间" />-->
          <!--        </el-form-item>-->
        </el-form>

        <div v-show="currentStep == 1">
          <div style="margin-bottom: 10px">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="mini"
              @click="handleAddEpisodes"
            >新增</el-button>
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="handleEmptyEpisodes"
            >清空</el-button>
          </div>
          <el-table v-loading="loading" :data="episodesList" height="300px" stripe @selection-change="handleSelectionChange">
<!--            <el-table-column type="selection" width="55" align="center" />-->
            <!--          <el-table-column label="" align="center" prop="id" />-->
            <!--          <el-table-column label="" align="center" prop="siteId" />-->
            <!--          <el-table-column label="语言" align="center" prop="langId" />-->
            <!--          <el-table-column label="短剧" align="center" prop="vid" />-->
            <el-table-column label="名称" align="center" prop="name" >
              <template slot-scope="scope">
                <el-input v-model="scope.row.name" />
              </template>
            </el-table-column>
<!--            <el-table-column label="封面" align="center" prop="image" width="100">-->
<!--              <template slot-scope="scope">-->
<!--                <image-preview :src="scope.row.image" :width="50" :height="50"/>-->
<!--              </template>-->
<!--            </el-table-column>-->
            <el-table-column label="视频" width="280px" align="center" prop="video" >
              <template slot-scope="scope">
                <el-input v-model="scope.row.video" />
              </template>
            </el-table-column>
            <el-table-column label="时长" align="center" prop="duration" >
              <template slot-scope="scope">
                <el-input v-model="scope.row.duration" />
              </template>
            </el-table-column>
            <el-table-column label="价格" align="center" prop="price" >
              <!-- 自定义表头内容 -->
              <template slot="header">
                <span>价格</span>
                <el-popover
                  placement="top"
                  width="160"
                  v-model="priceVisible"
                  @show="handlePriceShow"
                >
                  <el-input v-model="batchPrice" style="max-width: 100%;margin-bottom: 10px" />
                  <div style="text-align: right; margin: 0">
                    <el-button size="mini" type="text" @click="closePriceVisible">取消</el-button>
                    <el-button type="primary" size="mini" @click="batchEditPrice">确定</el-button>
                  </div>
                  <el-button slot="reference" size="mini" type="text" icon="el-icon-edit" @click="showPriceBatch"></el-button>
                </el-popover>
              </template>
              <template slot-scope="scope">
                <el-input v-model="scope.row.price" />
              </template>
            </el-table-column>
            <el-table-column label="VIP价格" width="100px" align="center" prop="vprice" >
              <!-- 自定义表头内容 -->
              <template slot="header">
                <span>VIP价格</span>
                <el-popover
                  placement="top"
                  width="160"
                  v-model="vpriceVisible"
                  @show="handlevPriceShow"
                >
                  <el-input v-model="vbatchPrice" style="max-width: 100%;margin-bottom: 10px" />
                  <div style="text-align: right; margin: 0">
                    <el-button size="mini" type="text" @click="closevPriceVisible">取消</el-button>
                    <el-button type="primary" size="mini" @click="batchEditvPrice">确定</el-button>
                  </div>
                  <el-button slot="reference" size="mini" type="text" icon="el-icon-edit"></el-button>
                </el-popover>
              </template>
              <template slot-scope="scope">
                <el-input v-model="scope.row.vprice" />
              </template>
            </el-table-column>
            <!--          <el-table-column label="销量" align="center" prop="sales" />-->
            <!--          <el-table-column label="点赞量" align="center" prop="likes" />-->
            <!--          <el-table-column label="播放量" align="center" prop="views" />-->
            <!--          <el-table-column label="收藏量" align="center" prop="favorites" />-->
            <!--          <el-table-column label="转发量" align="center" prop="shares" />-->
            <el-table-column label="排序" align="center" prop="weigh" >
              <template slot-scope="scope">
                <el-input v-model="scope.row.weigh" />
              </template>
            </el-table-column>
            <el-table-column label="商品状态" align="center" prop="status" >
              <template slot-scope="scope">
                <el-button
                  v-if="scope.row.status == 'normal'"
                  size="mini"
                  type="text"
                  @click="handleStatus(scope.row,'hidden')"
                >隐藏</el-button>
                <el-button
                  v-if="scope.row.status == 'hidden'"
                  size="mini"
                  type="text"
                  @click="handleStatus(scope.row,'normal')"
                >显示</el-button>
              </template>
            </el-table-column>
            <el-table-column label="虚拟点赞量" width="100px" align="center" prop="fakeLikes" >
              <template slot-scope="scope">
                <el-input v-model="scope.row.fakeLikes" />
              </template>
            </el-table-column>
            <el-table-column label="虚拟播放量" width="100px" align="center" prop="fakeViews" >
              <template slot-scope="scope">
                <el-input v-model="scope.row.fakeViews" />
              </template>
            </el-table-column>
            <el-table-column label="虚拟收藏量" width="100px" align="center" prop="fakeFavorites" >
              <template slot-scope="scope">
                <el-input v-model="scope.row.fakeFavorites" />
              </template>
            </el-table-column>
            <el-table-column label="虚拟转发量" width="100px" align="center" prop="fakeShares" >
              <template slot-scope="scope">
                <el-input v-model="scope.row.fakeShares" />
              </template>
            </el-table-column>
<!--            <el-table-column label="更新时间" align="center" prop="updatetime" />-->
<!--            <el-table-column label="添加时间" align="center" prop="createtime" />-->
<!--            <el-table-column label="删除时间" align="center" prop="deletetime" />-->
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDeleteEpis(scope.$index)"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>

        <el-form v-show="currentStep == 2" ref="form" :model="form" :rules="rules" label-width="80px">
          <el-form-item label="剧情简介" prop="description">
            <el-input type="textarea" :rows="5" v-model="form.description" placeholder="请输入简介" />
          </el-form-item>
          <!--        <el-form-item label="标签" prop="tags">-->
          <!--          <el-input v-model="form.tags" placeholder="请输入标签" />-->
          <!--        </el-form-item>-->
          <el-form-item label="图文详情">
            <editor v-model="form.content" :min-height="192"/>
          </el-form-item>

        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="prevStep" v-show="currentStep != 0">上一步</el-button>
        <el-button type="primary" @click="nextStep" v-show="currentStep < 2">下一步</el-button>
        <el-button @click="cancel" v-show="currentStep == 2">取 消</el-button>
        <el-button type="primary" @click="submitForm" v-show="currentStep == 2">确 定</el-button>
      </div>
    </el-dialog>

    <!-- 回收站管理 -->
    <el-dialog title="回收站" :visible.sync="openDel" append-to-body>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            icon="el-icon-refresh-right"
            size="mini"
            :disabled="single"
            @click="handleReduction"
          >还原</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            icon="el-icon-delete"
            size="mini"
            :disabled="single"
            @click="handleDestruction"
          >销毁</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            icon="el-icon-refresh-right"
            size="mini"
            @click="batchReduction"
          >还原全部</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            icon="el-icon-delete"
            size="mini"
            @click="batchDestruction"
          >清空回收站</el-button>
        </el-col>
      </el-row>
      <el-table v-loading="delLoading" :data="delList" stripe @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="标题" align="center" prop="title" />
        <el-table-column label="删除时间" align="center" prop="deletetime" />
        <el-table-column fixed="right" width="150px" label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="clickUpdateDel(scope.row)"
            >还原</el-button>
            <el-button
              size="mini"
              type="text"
              @click="clickDel(scope.row)"
            >销毁</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="delTotal>0"
        :total="delTotal"
        :page.sync="delParams.pageNum"
        :limit.sync="delParams.pageSize"
        @pagination="getList"
      />
    </el-dialog>

    <el-dialog :title="episodesTitle" :visible.sync="episodesFormVisible" width="500px" append-to-body>
      <el-form ref="episodesForm" :model="episodesForm" label-width="80px">
        <el-form-item label="视频" prop="video">
          <uploadLocal v-model="episodesForm.video"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitEpisodesForm">将上传的文件导出为Excel</el-button>
        <el-button @click="localCancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="ossTitle" :visible.sync="ossFormVisible" width="500px" append-to-body>
      <el-form ref="ossForm" :model="ossForm" label-width="80px">
        <el-form-item label="视频" prop="video">
          <uploadVideos v-model="ossForm.video"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitEpisodesForm">将上传的文件导出为Excel</el-button>
        <el-button @click="ossCancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        :data="{updateSupport:upload.updateSupport}"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
<!--        <div class="el-upload__tip" slot="tip">-->
<!--          <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的下井次数设置数据-->
<!--          <el-link-->
<!--            type="info"-->
<!--            style="font-size:12px"-->
<!--            @click="downloadTemplate('xjszTemplate.xlsx')"-->
<!--          >下载模板</el-link>-->
<!--        </div>-->
        <div
          class="el-upload__tip"
          style="color:red"
          slot="tip"
        >提示：仅允许导入“xls”或“xlsx”格式文件！</div>
      </el-upload>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { getToken } from "@/utils/auth";
import { listVideo, getVideo, delVideo, addVideo, updateVideo, batchUpdateVideo } from "@/api/video/video";
import {listLang} from "@/api/video/lang";
import {childrenList} from "@/api/video/category";
import {delEpisodes, getListEpisodes, listEpisodes, updateEpisodes} from "@/api/video/episodes";
import uploadVideos from "@/views/video/uploadVideos";
import uploadLocal from "@/views/video/uploadLocal";
export default {
  name: "Video",
  components: { uploadVideos, uploadLocal },
  data() {
    return {
      // 搜索条件按钮
      switchValue: false,
      //折叠面板绑定值
      collapseItem: false,
      // 语言绑定值
      langValue: '',
      // 标志绑定值
      flagValue: '',
      langList: [],
      // 分类绑定值
      categoryValue: '0',
      categoryList: [],
      categories: [],
      cList: [],
      // 遮罩层
      loading: true,
      delLoading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 短剧表格数据
      videoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        siteId: null,
        langId: null,
        categoryIds: null,
        areaId: null,
        yearId: null,
        title: null,
        subtitle: null,
        image: null,
        flags: null,
        description: null,
        tags: null,
        content: null,
        price: null,
        vprice: null,
        episodes: null,
        score: null,
        sales: null,
        favorites: null,
        views: null,
        shares: null,
        likes: null,
        fakeViews: null,
        fakeFavorites: null,
        fakeShares: null,
        fakeLikes: null,
        weigh: null,
        status: null,
        copyrightId: null,
        createtime: null,
        updatetime: null,
        deletetime: null,
        minprice: null,
        maxprice: null,
        minvprice: null,
        maxvprice: null
      },
      // 表单参数
      form: {},
      flagArray: [],
      // 步骤条属性
      currentStep: 0,
      // 剧集list
      episodesList: [],
      oldEpisList: [],
      // 表单校验
      rules: {
        // siteId: [
        //   { required: true, message: "站点id不能为空", trigger: "blur" }
        // ],
        langId: [
          { required: true, message: "语言id不能为空", trigger: "blur" }
        ],
        categoryIds: [
          { required: true, message: "分类id不能为空", trigger: "blur" }
        ],
        // areaId: [
        //   { required: true, message: "地区不能为空", trigger: "blur" }
        // ],
        // yearId: [
        //   { required: true, message: "年份不能为空", trigger: "blur" }
        // ],
        title: [
          { required: true, message: "标题不能为空", trigger: "blur" }
        ],
        // subtitle: [
        //   { required: true, message: "副标题不能为空", trigger: "blur" }
        // ],
        // image: [
        //   { required: true, message: "封面不能为空", trigger: "blur" }
        // ],
        // description: [
        //   { required: true, message: "简介不能为空", trigger: "blur" }
        // ],
        // tags: [
        //   { required: true, message: "标签不能为空", trigger: "blur" }
        // ],
        price: [
          { required: true, message: "价格不能为空", trigger: "blur" }
        ],
        vprice: [
          { required: true, message: "VIP价格不能为空", trigger: "blur" }
        ],
        episodes: [
          { required: true, message: "总集数不能为空", trigger: "blur" }
        ],
        // score: [
        //   { required: true, message: "评分不能为空", trigger: "blur" }
        // ],
        // sales: [
        //   { required: true, message: "销量不能为空", trigger: "blur" }
        // ],
        // favorites: [
        //   { required: true, message: "收藏量不能为空", trigger: "blur" }
        // ],
        // views: [
        //   { required: true, message: "播放量不能为空", trigger: "blur" }
        // ],
        // shares: [
        //   { required: true, message: "转发量不能为空", trigger: "blur" }
        // ],
        // likes: [
        //   { required: true, message: "点赞量不能为空", trigger: "blur" }
        // ],
        // fakeViews: [
        //   { required: true, message: "虚拟播放量不能为空", trigger: "blur" }
        // ],
        // fakeFavorites: [
        //   { required: true, message: "虚拟收藏量不能为空", trigger: "blur" }
        // ],
        // fakeShares: [
        //   { required: true, message: "虚拟转发量不能为空", trigger: "blur" }
        // ],
        // fakeLikes: [
        //   { required: true, message: "虚拟点赞量不能为空", trigger: "blur" }
        // ],
        // weigh: [
        //   { required: true, message: "排序不能为空", trigger: "blur" }
        // ],
        // status: [
        //   { required: true, message: "商品状态:up=上架,down=下架不能为空", trigger: "change" }
        // ],
        // copyrightId: [
        //   { required: true, message: "版权方不能为空", trigger: "blur" }
        // ],
        // createtime: [
        //   { required: true, message: "添加时间不能为空", trigger: "blur" }
        // ],
        // updatetime: [
        //   { required: true, message: "更新时间不能为空", trigger: "blur" }
        // ],
      },
      openBatch: false,
      checkedBatch: null,
      batchForm: {
        price: null,
        vprice: null,
        paid: null,
        paids: null,
        vpaid: null,
        vpaids: null,
        limit: null,
        vlimit: null,
      },
      priceVisible: false,
      batchPrice: '',
      vpriceVisible: false,
      vbatchPrice: '',
      openDel: false,
      delList: [],
      delTotal: 0,
      delParams: {
        pageNum: 1,
        pageSize: 10,
        deletetime: 1,
      },
      episodesForm: {},
      episodesFormVisible: false,
      episodesTitle: '',
      ossForm: {},
      ossFormVisible: false,
      ossTitle: '',
      // 导入参数
      upload: {
        // 是否显示弹出层
        open: false,
        // 弹出层标题
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/video/episodes/importData",
      },
    };
  },
  created() {
    this.getList();
    this.getLangList();
  },
  methods: {
    getLangList() {
      this.loading = true;
      listLang().then(response => {
        this.langList = response.rows;
        if(this.langValue) {
          this.queryParams.langId = this.langValue;
          this.getCategoryList();
        }
        this.loading = false;
      });
    },
    /** 查询商城分类列表 */
    getCategoryByLangList() {
      if(this.langValue == '') {
        this.categoryValue = '';
        this.queryParams.categoryIds = null;
        this.getList();
      } else {
        this.loading = true;
        let category = {
          langId: this.langValue
        }
        childrenList(category).then(response => {
          if(response.rows.length != 0) {
            this.categoryList = response.rows;
          } else {
            this.categoryList = []
          }
          this.loading = false;
        });
      }
    },
    getCategoryList() {
      this.queryParams.categoryIds = this.categoryValue;
      this.getList();
    },
    getFlagList() {
      this.queryParams.flags = this.flagValue;
      this.getList();
    },
    /** 查询短剧列表 */
    getList() {
      this.loading = true;
      listVideo(this.queryParams).then(response => {
        this.videoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getEpisodes() {
      let params = {
        vid: this.form.id
      }
      getListEpisodes(params).then(response => {
        this.episodesList = response.rows;
        this.oldEpisList = JSON.parse(JSON.stringify(response.rows));
        this.open = true;
        this.title = "修改短剧";
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.episodesList = [];
      this.currentStep = 0;
      this.oldEpisList = [];
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        siteId: null,
        langId: null,
        categoryIds: null,
        areaId: null,
        yearId: null,
        title: null,
        subtitle: null,
        image: null,
        flags: null,
        description: null,
        tags: null,
        content: null,
        price: null,
        vprice: null,
        episodes: null,
        score: null,
        sales: null,
        favorites: null,
        views: null,
        shares: null,
        likes: null,
        fakeViews: null,
        fakeFavorites: null,
        fakeShares: null,
        fakeLikes: null,
        weigh: null,
        status: null,
        copyrightId: null,
        createtime: null,
        updatetime: null,
        deletetime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.resetForm("queryForm");
      this.langValue = ''
      this.categoryValue = ''
      this.flagValue = ''
      // 查询参数
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        siteId: null,
        langId: null,
        categoryIds: null,
        areaId: null,
        yearId: null,
        title: null,
        subtitle: null,
        image: null,
        flags: null,
        description: null,
        tags: null,
        content: null,
        price: null,
        vprice: null,
        episodes: null,
        score: null,
        sales: null,
        favorites: null,
        views: null,
        shares: null,
        likes: null,
        fakeViews: null,
        fakeFavorites: null,
        fakeShares: null,
        fakeLikes: null,
        weigh: null,
        status: null,
        copyrightId: null,
        createtime: null,
        updatetime: null,
        deletetime: null,
        minprice: null,
        maxprice: null,
        minvprice: null,
        maxvprice: null
      }
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    changeLangCategory() {
      let params = {
        langId: this.form.langId
      }
      childrenList(params).then(response => {
        if(response.rows.length != 0) {
          this.cList = response.rows;
          if (this.form.categoryIds) {
            this.categories = this.form.categoryIds.split(",");
          }
        } else {
          this.cList = []
        }
      });
    },
    handleAddEpisodes() {
      let params = {}
      this.oldEpisList.push(params)
      this.episodesList.push(params);
    },
    handleEmptyEpisodes() {
      this.oldEpisList.forEach(item => item.isDelete = true);
      this.episodesList = [];
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加短剧";
    },
    showPriceBatch() {
      this.priceVisible = !this.priceVisible;
    },
    handlePriceShow() {
      this.batchPrice = ''
    },
    batchEditPrice() {
      this.episodesList.forEach(item => item.price = this.batchPrice);
      this.closePriceVisible();
    },
    closePriceVisible() {
      console.log(this.batchPrice)
      // this.batchPrice = '';
      this.priceVisible = false;
      console.log(this.priceVisible)
    },
    showvPriceBatch() {
      this.vpriceVisible = true;
    },
    batchEditvPrice() {
      this.episodesList.forEach(item => item.vprice = this.vbatchPrice)
    },
    closevPriceVisible() {
      // this.vbatchPrice = '';
      this.vpriceVisible = false;
    },
    handlevPriceShow() {
      this.vbatchPrice = ''
    },
    /** 上下架按钮 */
    handleUpDown(row,str) {
      row.status = str
      updateVideo(row).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.open = false;
        this.getList();
      });
    },
    handleStatus(row, str) {
      row.status = str
    },
    /** 修改按钮操作 */
    async handleUpdate(row) {
      this.form = row;
      this.flagArray = this.form.flags.split(",")
      this.categories = this.form.categoryIds.split(",");
      await this.changeLangCategory();
      await this.getEpisodes();
    },
    /** 复制按钮操作 */
    async handleCopy(row) {
      this.form = row;
      this.flagArray = this.form.flags.split(",")
      this.categories = this.form.categoryIds.split(",");
      await this.changeLangCategory();
      await this.getEpisodes();
    },
    getDelList() {
      this.delLoading = true;
      listVideo(this.delParams).then(response => {
        this.delList = response.rows;
        this.delTotal = response.total;
        this.delLoading = false;
      });
    },
    handleOpenDelete() {
      this.getDelList();
      this.openDel = true;
    },
    prevStep() {
      if(this.currentStep > 0) {
        this.currentStep--;
      }
    },
    nextStep() {
      if (this.currentStep < 2) {
        this.currentStep++;
      }
    },
    openBatchDialog() {
      this.openBatch = true
      this.batchForm = {
        price: null,
        vprice: null,
        paid: null,
        paids: null,
        vpaid: null,
        vpaids: null,
        limit: null,
        vlimit: null
      }
    },
    cancelBatch() {
      this.openBatch = false
      this.batchForm = {
        price: null,
        vprice: null,
        paid: null,
        paids: null,
        vpaid: null,
        vpaids: null,
        limit: null,
        vlimit: null
      }
    },
    changeVip() {
      if(this.checkedBatch) {
        this.batchForm = {
          vprice: 0,
          vpaid: 0,
          vpaids: null,
          vlimit: null
        }
      } else {
        this.batchForm = {
          vprice: null,
          vpaid: null,
          vpaids: null,
          vlimit: null
        }
      }
    },
    batchUpdateVideo() {
      if(this.batchForm.limit == null && this.batchForm.paid != null || this.batchForm.limit != null && this.batchForm.paid == null) {
        this.$modal.msgSuccess("集数或对应价格为空");
        return
      }
      if(this.checkedBatch) {
        this.batchForm.vprice = 0
        this.batchForm.vpaid = null
        this.batchForm.vlimit = null
        this.batchForm.vpaids = 0
      }
      batchUpdateVideo(this.batchForm).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.openBatch = false;
        this.getList();
      })
    },
    /** 提交按钮 */
    submitForm() {
      if (!this.form.langId) {
        this.$modal.msgError("请选择语言");
        return;
      }
      if (!this.form.title) {
        this.$modal.msgError("请输入视频标题");
        return;
      }
      if(this.flagArray.length > 0) {
        this.form.flags = this.flagArray.toString()
      } else {
        this.$modal.msgError("请选择视频标签");
        return;
      }
      if(this.categories.length > 0) {
        this.form.categoryIds = this.categories.toString()
      } else {
        this.$modal.msgError("请选择视频分类");
        return;
      }
      if (this.form.price == null || this.form.price == '' && this.form.price != 0) {
        this.$modal.msgError("请输入剧集总价");
        return;
      }
      if (this.form.vprice == null || this.form.vprice == '' && this.form.vprice != 0) {
        this.$modal.msgError("请输入VIP剧集总价");
        return;
      }
      if (!this.form.episodes) {
        this.$modal.msgError("请输入剧集数量");
        return;
      }
      let errors = [];
      if (this.episodesList.length != 0) {
        for (let item of this.episodesList) {
          if (!item.name) {
            errors.push("名称不能为空");
            break; // 发现错误，立即跳出循环
          }
          if (item.price == null || item.price == '' && item.price != 0) {
            errors.push("积分价格不能为空");
            break; // 发现错误，立即跳出循环
          }
          if (item.vprice == null || item.vprice == '' && item.vprice != 0) {
            errors.push("VIP积分价格不能为空");
            break; // 发现错误，立即跳出循环
          }
          if (!item.video) {
            errors.push("视频链接不能为空");
            break; // 发现错误，立即跳出循环
          }
          if (item.price != 0 || this.form.price != 0) {
            if (item.price > this.form.price) {
              errors.push("单集积分价格不能大于剧集积分总价");
              break; // 发现错误，立即跳出循环
            }
          }
          if (item.vprice != 0 || this.form.vprice != 0) {
            if (item.vprice > this.form.vprice) {
              errors.push("VIP单集积分价格不能大于剧集积分总价");
              break; // 发现错误，立即跳出循环
            }
          }
        }

        if (errors.length > 0) {
          // 一旦发现错误，立即弹出提示并结束程序
          this.$modal.msgWarning(errors);
          // 如果需要结束程序，可以在此处添加 window.close() 或其他适当的退出机制
          return; // 结束当前函数的执行
        } else {
          // 如果没有错误，判断是否有剧集信息，如果没有就不做处理
          if (this.episodesList.length > 0) {
            this.episodesList.forEach(item => updateEpisodes(item));
          }
        }
      }
      // 如果存在错误，则弹出错误提示
      if (errors.length > 0) {
        this.$modal.msgWarning(errors);
        return;
      } else {

        const deletedItems = this.oldEpisList.filter(item => item.isDelete);
        if(deletedItems.length > 0) {
          deletedItems.forEach(item => delEpisodes(item.id));
        }

        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateVideo(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addVideo(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });

      }
    },
    /** 删除按钮操作 */
    handleChangeDel(row) {
      row.deletetime = '1'
      updateVideo(row).then(response => {
        this.$modal.msgSuccess("删除成功");
        this.open = false;
        this.getList();
      });
    },
    handleDeleteEpis(index) {
      this.oldEpisList[index].isDelete = true;
      this.episodesList.splice(index,1);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除短剧编号为"' + ids + '"的数据项？').then(function() {
        return delVideo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/video/export', {
        ...this.queryParams
      }, `video_${new Date().getTime()}.xlsx`)
    },
    clickUpdateDel(row) {
      row.deletetime = null
      updateVideo(row).then(response => {
        this.$modal.msgSuccess("删除成功");
        this.open = false;
        this.getList();
      });
    },
    clickDel(row) {
      const ids = [];
      ids.push(row.id)
      this.$modal.confirm('是否确认删除短剧编号为"' + ids + '"的数据项？').then(function() {
        return delVideo(ids);
      }).then(() => {
        this.getDelList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    // 多选后点击还原的事件
    handleReduction() {
      let num = 0;
      this.ids.forEach(id => {
        let params = {
          id: id,
          deletetime: null
        }
        updateVideo(params).then(response => {
        }).catch(e => {
          num++;
        });
      })
      if(num == 0) {
        this.$modal.msgSuccess("还原成功");
        this.getDelList();
      }
    },
    // 多选后点击删除的事件
    handleDestruction() {
      const ids = this.ids;
      this.$modal.confirm('是否确认删除短剧编号为"' + ids + '"的数据项？').then(function() {
        return delVideo(ids);
      }).then(() => {
        this.getDelList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    // 还原回收站全部数据的事件
    batchReduction() {
      if(this.delList.length > 0) {
        let num = 0;
        this.delList.forEach(item => {
          item.deletetime = null
          updateVideo(item).then(response => {
          }).catch(e => {
            num++;
          });
        })
        if(num == 0) {
          this.$modal.msgSuccess("还原成功");
          this.getDelList();
        }
      } else {
        this.$modal.msgWarning("回收站暂无数据");
      }
    },
    // 删除回收站全部数据的事件
    batchDestruction() {
      if(this.delList.length > 0) {
        const ids = this.delList.map(obj => obj.id);
        this.$modal.confirm('是否确认删除回收站中的全部数据？').then(function() {
          return delVideo(ids);
        }).then(() => {
          this.getDelList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      } else {
        this.$modal.msgWarning("回收站已经是空的了");
      }
    },
    importEpisodes() {
      this.episodesFormVisible = true;
      this.episodesTitle = "上传本地";

    },
    submitEpisodesForm() {
      this.download('video/episodes/exportLocal', {
        ...this.episodesForm
      }, `video_${new Date().getTime()}.xlsx`)
    },
    importOss() {
      this.ossFormVisible = true;
      this.ossTitle = "上传oss";

    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    submitFileForm() {
      this.$refs.upload.submit();
    },
    localCancel() {
      this.episodesFormVisible = false;
      this.episodesForm = {};
    },
    ossCancel() {
      this.ossFormVisible = false;
      this.ossForm = {};
    }
  }
};
</script>
<style scoped>
.el-input {
  width: 200px !important;
}
.downClass {
  color: #727272;
}
el-dialog__body {
  height: 700px !important;
}
.el-row{
  display: flex;
}
</style>
